package main

import (
	"container/list"
	"log"

	"github.com/PuerkitoBio/goquery"
)

type Films struct {
	Poster     string
	Name       string
	PutTime    string
	Resolution string
	Type       list.List
	Area       list.List
	Language   string
	Imdb       string
	Actor      list.List
	Introduce  string
	DetailImg  list.List
	Score      string
	URL        FilmLink
}
type FilmLink struct {
	Ts     string
	TsLink string
	HD     string
	HDLink string
	BD     string
	BDLink string
}

func GetFilms() {
	host := "http://www.btbtdy.com"
	url := "http://www.btbtdy.com/btfl/dy1.html"
	doc, err := goquery.NewDocument(url)
	if err != nil {
		log.Fatal(err)
	}
	doc.Find("div.liimg > a.pic_link").Each(func(i int, s *goquery.Selection) {

		href, _ := s.Attr("href")
		detail, err := goquery.NewDocument(host + href)
		if err != nil {
			log.Fatal(err)
		}

		film := Film{}

		//海报URL  电影名字
		detail.Find("div.vod_img lf > img").Each(func(i int, selection *goquery.Selection) {
			img, _ := selection.Attr("src")

			film.Poster = img
			name, _ := selection.Attr("alt")
			film.Name = name
			log.Println(name)
		})

		detail.Find("div.vod_intro rt > dl > dd").Each(func(i int, s *goquery.Selection) {
			// 更新时间
			time := s.First().Text()
			film.PutTime = time
			//dip
			dip := s.Eq(1).Text()
			film.Resolution = dip
			//类型
			typeList := list.List{}
			s.Eq(2).Find("a").Each(func(i int, s *goquery.Selection) {

				typeList.PushBack(s.Text())
			})
			film.Type = typeList
			//地区
			areaList := list.List{}
			s.Eq(3).Find("a").Each(func(i int, selection *goquery.Selection) {
				areaList.PushBack(selection.Text())
			})
			film.Area = areaList
			//语言
			film.Language = s.Eq(4).Find("a").Text()
			//imdb
			film.Imdb = s.Eq(5).Text()
			//主演
			actorLis := list.List{}
			s.Eq(6).Find("a").Each(func(i int, s *goquery.Selection) {
				actorLis.PushBack(s.Text())
			})
			film.Actor = actorLis
			//介绍
			c := ""
			s.Find("div.des>div.c05>span").Each(func(i int, s *goquery.Selection) {
				c += s.Text() + "\n"
			})

		})

	})

}

func main() {
	GetFilms()
}
